package com.emep.changzhi.analyse.service.basics;

import com.emep.changzhi.analyse.entity.basics.SysEmissionStandardFineInfo;
import com.emep.changzhi.analyse.repository.basics.SysEmissionStandardFineInfoRepository;
import com.emep.changzhi.analyse.utils.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author Wangcc
 * @version V1.0
 * @Description: 排放标准细则业务层
 * @date 2018/2/26 15:45
 */
@Service
public class SysEmissionStandardFineInfoService {
    
    @Resource
    private SysEmissionStandardFineInfoRepository sysEmissionStandardFineInfoRepository;

    private static final Logger logger = LoggerFactory.getLogger(SysEmissionStandardFineInfoService.class);


    /**
     *
     * 不含查询条件的分页获取数据
     *
     * @param pageNo
     * @param pageSize
     * @return
     * @throws Exception
     */
    public Page<SysEmissionStandardFineInfo> findAll(Integer pageNo, Integer pageSize){
        try {
            Pageable pageable = new PageRequest(pageNo-1, pageSize);
            return  sysEmissionStandardFineInfoRepository.findAll(pageable);
        } catch (Exception e) {
            logger.error(e.getLocalizedMessage());
            return null;
        }
    }

    /**
     *
     * 新增排放标准细则
     *
     * @param payload
     * @return
     * @throws Exception
     */
    public SysEmissionStandardFineInfo save(Map<String, Object> payload) {
        SysEmissionStandardFineInfo SysEmissionStandardFineInfo = null;
        try {
            SysEmissionStandardFineInfo SysEmissionStandardFineInfo1 = (SysEmissionStandardFineInfo) MapUtils.convertMap(SysEmissionStandardFineInfo.class,payload);
            SysEmissionStandardFineInfo = sysEmissionStandardFineInfoRepository.save(SysEmissionStandardFineInfo1);
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
        }
        return SysEmissionStandardFineInfo;
    }


    /**
     *
     * 根据id查询排放标准细则
     *
     * @param id
     * @return
     */
    public SysEmissionStandardFineInfo findId(String id){
        SysEmissionStandardFineInfo sysEmissionStandardFineInfo = null;
        try {

            sysEmissionStandardFineInfo = sysEmissionStandardFineInfoRepository.findSysEmissionStandardFineInfoById(id);
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
        }
        return sysEmissionStandardFineInfo;
    }

    /**
     *
     * 根据id 删除排放标准细则
     *
     * @param id
     */
    public Boolean delete(String id) {
        Boolean result = false;
        try {
            Integer result1 = sysEmissionStandardFineInfoRepository.deleteById(id);
            if(result1 == 1){
                result = true;
            }
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
        }
        return result;
    }

    /**
     *查询所有排放标准细则
     *
     * @return List<SysEmissionStandardFineInfo>
     */
    public List<SysEmissionStandardFineInfo> findAll() {
        List<SysEmissionStandardFineInfo> SysEmissionStandardFineInfos = null;
        try {
            SysEmissionStandardFineInfos =  sysEmissionStandardFineInfoRepository.findAll();
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
        }
        return SysEmissionStandardFineInfos;
    }

}
